package com.cloud.demo.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@Slf4j
public class DemoController {


    /**
     * 项目启动后执行一次
     *
     * @throws Exception
     */
    @PostConstruct
    public void onStart() throws Exception {
        log.info("启动执行");
        new Thread(() -> {
            try {
                Thread.sleep(60000);
                statisticsBasisTableInfo();
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }).start();
    }

    @Scheduled(cron = "0 0 18 * * ?")
    public void statisticsBasisTableInfo() throws Exception {
        System.out.println("-----调度-------");
    }


    /**
     * 每周一执行一次 0 18 16 * * THU
     */

    @Scheduled(cron = "0 18 16 * * THU")
    public void exeEveryWeek() {
        LocalDateTime date = LocalDateTime.now();
        String dateTime = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.info(dateTime);
        log.info("定时---------------------------");
    }


}
